import os
from launch import LaunchDescription
from launch_ros.actions import Node
from launch.actions import DeclareLaunchArgument
from launch.substitutions import LaunchConfiguration
from ament_index_python.packages import get_package_share_directory


def generate_launch_description():
    # Declare launch arguments with default values
    image_rect_arg = DeclareLaunchArgument(
        "image_rect",
        default_value="/camera/image_raw",
        description="Remapped topic for rectified image",
    )

    camera_info_arg = DeclareLaunchArgument(
        "camera_info",
        default_value="/camera/camera_info",
        description="Remapped topic for camera info",
    )

    params_file_arg = DeclareLaunchArgument(
        "params_file",
        default_value=os.path.join(
            get_package_share_directory("apriltag_ros"),
            "cfg",
            "tags_36h11.yaml",
        ),
        description="Path to the parameter file",
    )

    # Node configuration
    apriltag_node = Node(
        package="apriltag_ros",
        executable="apriltag_node",
        name="apriltag_node",
        remappings=[
            ("image_rect", LaunchConfiguration("image_rect")),
            ("camera_info", LaunchConfiguration("camera_info")),
        ],
        parameters=[LaunchConfiguration("params_file")],
    )

    # Combine all into a launch description
    return LaunchDescription([image_rect_arg, camera_info_arg, params_file_arg, apriltag_node])
